// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import settingMediator from "../../framework/settingMediator";
import Tool from "../../framework/Tool";
import gameData from "../gameData";
import languageManager from "../languageManager/languageManager";

const {ccclass, property} = cc._decorator;

@ccclass
export default class settingView extends cc.Component {

    @property(cc.Slider)
    bgmSlider : cc.Slider = null;

    @property(cc.Slider)
    musicSlider : cc.Slider = null;

    onLoad () {

        this.bgmSlider.progress = settingMediator.getBgmVolume();
        this.musicSlider.progress = settingMediator.getVoiceVolume();
        this.bgmSlider.node.getChildByName("ProgressBar").getComponent(cc.ProgressBar).progress = settingMediator.getBgmVolume();
        this.musicSlider.node.getChildByName("ProgressBar").getComponent(cc.ProgressBar).progress = settingMediator.getVoiceVolume();
    }

    protected start(): void {

    }

    vibrationSwitch(event,data){

        if(parseInt(data) == 1){
            settingMediator.vibrationStatus = true;
            console.log("打开震动");
        }

        if(parseInt(data) == 2){
            settingMediator.vibrationStatus = false;
            console.log("关闭震动");
        }
    }


    callback = null;
    closeWindow(){
        this.node.destroy();
        if(this.callback != null){
            this.callback();
        }
    }

    setCallBack(callback){
        this.callback = callback;
    }

    setBgmVoice(){
        let progress = this.bgmSlider.progress;
        this.bgmSlider.node.getChildByName("ProgressBar").getComponent(cc.ProgressBar).progress = progress;
        settingMediator.setBgmVolume(progress);
    }

    setMusicVoice(){
        let progress = this.musicSlider.progress;
        this.musicSlider.node.getChildByName("ProgressBar").getComponent(cc.ProgressBar).progress = progress;
        settingMediator.setVoiceVolume(progress);
    }
}
